package cn.cubic.sys.modular.buyrelation.controller;

import cn.cubic.core.annotion.BusinessLog;
import cn.cubic.core.enums.LogAnnotionOpTypeEnum;
import cn.cubic.core.pojo.response.ResponseData;
import cn.cubic.core.pojo.response.SuccessResponseData;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import cn.cubic.sys.modular.buyrelation.service.BuyRelationService;
import cn.cubic.sys.modular.buyrelation.model.param.BuyRelationParam;

import javax.annotation.Resource;

/**
 * 购买关系表 控制器
 */
@RestController
public class BuyRelationController {

    @Resource
    private BuyRelationService buyRelationService;

    /**
     * 分页查询购买关系表
     */
    @GetMapping("/buyRelation/page")
    @BusinessLog(title = "购买关系表_分页查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData page(BuyRelationParam buyRelationParam) {
        return new SuccessResponseData(buyRelationService.page(buyRelationParam));
    }

    /**
     * 获取全部购买关系表
     */
    @GetMapping("/buyRelation/list")
    @BusinessLog(title = "购买关系表_查询所有", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list(BuyRelationParam buyRelationParam) {
        return new SuccessResponseData(buyRelationService.list(buyRelationParam));
    }

    /**
     * 查看详情购买关系表
     */
    @GetMapping("/buyRelation/detail")
    @BusinessLog(title = "购买关系表_查看详情", opType = LogAnnotionOpTypeEnum.DETAIL)
    public ResponseData detail(@Validated(BuyRelationParam.detail.class) BuyRelationParam buyRelationParam) {
        return new SuccessResponseData(buyRelationService.detail(buyRelationParam));
    }

    /**
     * 添加购买关系表
     */
    @PostMapping("/buyRelation/add")
    @BusinessLog(title = "购买关系表_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody @Validated(BuyRelationParam.add.class) BuyRelationParam buyRelationParam) {
        buyRelationService.add(buyRelationParam);
        return new SuccessResponseData();
    }

    /**
     * 删除购买关系表
     */
    @PostMapping("/buyRelation/delete")
    @BusinessLog(title = "购买关系表_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated(BuyRelationParam.delete.class) BuyRelationParam buyRelationParam) {
        buyRelationService.delete(buyRelationParam);
        return new SuccessResponseData();
    }

    /**
     * 编辑购买关系表
     */
    @PostMapping("/buyRelation/edit")
    @BusinessLog(title = "购买关系表_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody @Validated(BuyRelationParam.edit.class) BuyRelationParam buyRelationParam) {
        buyRelationService.edit(buyRelationParam);
        return new SuccessResponseData();
    }


}
